<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\adminapi\controller\v1\shop;

use app\adminapi\controller\AuthController;
use app\services\shop\ShopServices;
use think\facade\App;

/**
 * 店铺管理
 * Class Article
 * @package app\adminapi\controller\v1\cms
 */
class Shop extends AuthController
{
    /**
     * @var ShopServices
     */
    protected $service;

    /**
     * Article constructor.
     * @param App $app
     * @param ShopServices $service
     */
    public function __construct(App $app, ShopServices $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    /**
     * 获取列表
     * @return mixed
     */
    public function index()
    {
        $where = $this->request->getMore([
        ]);
        $data = $this->service->getList($where);
        if($data['count'] > 0){
            foreach ($data['list'] as $key => $item){
                unset($data['list'][$key]['author']);
            }
        }
        return app('json')->success($data);
    }

    /**
     * 保存数据
     * @return mixed
     */
    public function save($id = 0)
    {
        $data = $this->request->postMore([
            ['id', $id],
            ['name', ''],
            ['address', ''],
            ['start_time', ''],
            ['end_time', ''],
            ['admin_id',$this->adminId],
            ['admin_name',$this->adminInfo['real_name']],
        ]);
        $this->service->save($data);
        return app('json')->success(100021);
    }

    /**
     * 删除
     * @param int $id
     * @return mixed
     */
    public function delete($id)
    {
        if (!$id) return app('json')->fail(100100);
        $this->service->del($id);
        return app('json')->success(100002);
    }

    /**
     * 保存设置
     * @return mixed
     */
    public function set($id)
    {
        $param = $this->request->postMore([
            ['id', $id],
            ['type', ''],
            ['status', 0],
        ]);

        if($param['type'] == ''){
            return app('json')->fail(100100);
        }
        $data['id'] = $param['id'];
        $data[$param['type']] = $param['status'];
        $this->service->save($data);
        return app('json')->success(100000);
    }
}
